package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.et.mvc.JsonView;

import DAO.ReportManagementDAO;

/**
 * Servlet implementation class getAssetDetailsServlet
 */
public class getAssetDetailsServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public getAssetDetailsServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	    request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/plain");
		PrintWriter out = response.getWriter();
		
        int start = Integer.parseInt(request.getParameter("start"));
        int limit = Integer.parseInt(request.getParameter("limit"));
        

        String state = request.getParameter("state");
        String type = request.getParameter("type");
        String department = request.getParameter("department");
        String name = request.getParameter("name");
        String startUseTime = request.getParameter("startUseTime");
        String endUseTime = request.getParameter("endUseTime");
        
        ReportManagementDAO getADDAO = new ReportManagementDAO();
        
        @SuppressWarnings("unused")
		List getADSelectList = null;
        Map<String,Object> map = new HashMap<String,Object>();        
        
        if(state.equals("") && type.equals("") && department.equals("") 
           && name.equals("") && startUseTime.equals("") && endUseTime.equals(""))
        {
        	getADSelectList = getADDAO.getAllAsset(start , limit);       	         	 
        }           
        else
        {
        	getADSelectList = getADDAO.getAssetByQuery(start, limit, name, type, state, department, startUseTime, endUseTime);      	
        }
        map.put("result",getADSelectList);
        map.put("total",getADDAO.count);
                  
        out.print(new JsonView(map));		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
